class Instructions {
    /**
     * 获取roles
     * @api {GET}         /              获取roles
     * @apiName           /instructions
     * @apiGroup          Instructions
     * @apiVersion 0.1.0
     * @apiSuccessExample Success-Response:
     * {
        "code": 0,
        "msg": "success",
        "data": {
            "createdAt": "2019-06-10T09:07:17.000Z"
            "id": 1
            "share": 3
            "updatedAt": "2019-06-10T09:07:20.000Z"
            "wash": 3
        }
       }
     */
    async index(ctx) {
        const { db } = ctx;
        let data = await db.Instructions.findOne();
        ctx.success(data);
    }
    /**
     * 保存roles
     * @api {PUT}         /:id                   保存roles
     * @apiName           /instructions
     * @apiGroup          Instructions
     * @apiParam          {String}       membersRoles     会员规则
     * @apiParam          {String}       timeCardRoles    次卡规则
     * @apiParam          {String}       shareRoles       分享规则
     * @apiVersion 0.1.0
     * @apiSuccessExample Success-Response:
     * {
        "code": 0,
        "msg": "success",
        "data": {}
       }
     */
    async edit(ctx) {
        const {
            db,
            params: { id },
            request: {
                body: { membersRoles, timeCardRoles, shareRoles }
            }
        } = ctx;

        let data = await db.Instructions.findOne({ where: { id: id } });
        data.membersRoles = membersRoles;
        data.timeCardRoles = timeCardRoles;
        data.shareRoles = shareRoles;
        data.save();
        ctx.success();
    }
}
module.exports = new Instructions();
